//
//  DingDanDetailViewController2.m
//  Experss
//
//  Created by wmwMAC on 17/8/11.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "DingDanDetailViewController2.h"

#import "DingDanDetailImgTableViewCell.h"
#import "DingDanDetailLocationTableViewCell.h"
#import "DingDanDetailGoodsTableViewCell.h"
#import "DingDanFollowTableViewCell.h"
#import "DingDanFollwContentTableViewCell.h"

//#import "TiJIaoDingDanViewController.h"//提交订单
//#import "MyAddressViewController.h"// 添加地址


static NSString *ImgIdentifier = @"DingDanDetailImgTableViewCell";
static NSString *LocationIdentifier = @"DingDanDetailLocationTableViewCell";
static NSString *GoodsIdentifier = @"DingDanDetailGoodsTableViewCell";
static NSString *FollowIdentifier = @"DingDanFollowTableViewCell";
static NSString *FollowContentIdentifier = @"DingDanFollwContentTableViewCell";

@interface DingDanDetailViewController2 ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong)UIButton *rightBtn;

@end

@implementation DingDanDetailViewController2

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BaseColor;
    
    self.navigationItem.title = @"订单详情";
    
    [self addTableviewUI];
}


- (void)addTableviewUI {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height-50) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = BaseColor;
    [self.tableView registerNib:[UINib nibWithNibName:@"DingDanDetailImgTableViewCell" bundle:nil] forCellReuseIdentifier:ImgIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:@"DingDanDetailLocationTableViewCell" bundle:nil]forCellReuseIdentifier:LocationIdentifier];
    [self.tableView registerClass:[DingDanDetailGoodsTableViewCell class] forCellReuseIdentifier:GoodsIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:@"DingDanFollowTableViewCell" bundle:nil]forCellReuseIdentifier:FollowIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:@"DingDanFollwContentTableViewCell" bundle:nil]forCellReuseIdentifier:FollowContentIdentifier];
    
    [self.view addSubview:self.tableView];
    _tableView.separatorStyle = kSpNone;
    
    
    UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight-50, kScreenWidth, 50)];
    footView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:footView];
    UIButton *confirmBtn = [BasePublicCreatUI createBtnFrame:CGRectMake(kScreenWidth-100, 10, 80, 30) title:@"确认送达" bgImage:nil selectBgImage:nil image:nil target:self action:@selector(confirmArrave)];
    [confirmBtn setTitleColor:BaseBlueColor forState:UIControlStateNormal];
    confirmBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    confirmBtn.layer.borderWidth = 1;
    confirmBtn.layer.cornerRadius = 30/2.0;
    confirmBtn.layer.borderColor = BaseBlueColor.CGColor;
    confirmBtn.clipsToBounds = YES;
    [footView addSubview:confirmBtn];
    
    
    
    //设置导航栏按钮的边距
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame= CGRectMake(0, 0, 60, 30);
    [rightBtn setImage:[UIImage imageNamed:@"all_fanhui2"] forState:(UIControlStateNormal)];
    [rightBtn addTarget:self action:@selector(handleBackBtn) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btn_left = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    UIBarButtonItem *negativeSpacerleft = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    /**
     width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和  边界间距为5pix，所以width设为-5时，间距正好调整为0；width为正数 时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacerleft.width = -20;
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacerleft, btn_left, nil];
    
    
    
}
- (void)handleBackBtn {
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)confirmArrave{
    NSLog(@"confirmArrave");
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 80;
        }else if (indexPath.row == 1){
            return 80;
        }else if (indexPath.row == 2){
            return 100;
        }else {
            return  47 + (kScreen_Width - 40 - 30 - 40)/5.0 + 26+6 + 40;
            
        }
    }else{
        return 50;
    }
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 4;
    }else{
        return 4;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            DingDanDetailImgTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ImgIdentifier forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }else if (indexPath.row == 1){
            DingDanDetailLocationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LocationIdentifier forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.lineImgView.hidden = YES;
            cell.lineView.backgroundColor = [UIColor whiteColor];
            cell.locationImgView.image = [UIImage imageNamed:@"qu"];
            
            return cell;
        }else if (indexPath.row == 2){
            DingDanDetailLocationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LocationIdentifier forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.lineImgView.hidden = NO;
            cell.lineView.backgroundColor = BaseColor;
            cell.locationImgView.image = [UIImage imageNamed:@"song"];
            
            
            return cell;
        }else{
            DingDanDetailGoodsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:GoodsIdentifier forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.titleLabel.font = [UIFont systemFontOfSize:14];
            cell.priceLabel.font = [UIFont systemFontOfSize:14];
            
            
            
            return cell;

        }
    }else {
        
        if (indexPath.row == 0) {
            DingDanFollowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FollowIdentifier forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }else{
            
            
            DingDanFollwContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FollowContentIdentifier forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.accessoryType = UITableViewCellAccessoryNone;
            
            
            if (indexPath.row == 1) {
                cell.headImgView.hidden = YES;
                cell.centerImgView.image = [UIImage imageNamed:@"wuliu_quan1"];
                cell.StateLable.textColor = BaseBlueColor;
            }else{
                cell.headImgView.hidden = NO;
                cell.centerImgView.image = [UIImage imageNamed:@"wuliu_quan2"];
                cell.StateLable.textColor = [UIColor lightGrayColor];
            }
            
            return cell;
            
        }

        
    
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    //    if (section == 0) {
    //
    //        return 40;
    //    }else {
    return 0.01;
    //    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = BaseColor;
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (section ==1) {
        return 0;
    }else {
        return 10;
    }
    
    
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *footview = [[UIView alloc] init];
    footview.backgroundColor = BaseColor;
    
    return footview;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 1) {
        //选择地址
        
    }
}


@end
